﻿using Publicuse.Entity;
using Publicuse.Entity.AttributeUtil;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Util
{
    public class BusinessAttributeUtil
    {
        public static string GetAttributeName<T>(BusinessType businessType)
        {
            string typename = string.Empty;
            string value = businessType.ToString();
            var info = businessType.GetType().GetField(value);
            var data = info.GetCustomAttributes(typeof(BusinessAttribute), false);
            if (data != null && data.Length > 0)
            {
                BusinessAttribute business = data[0] as BusinessAttribute;
                return business?.BusinessTypeName;
            }
            return value;
        }
        public static string GetAttributeName<T>(BusinessActionType businessActionType)
        {
            string typename = string.Empty;
            string value = businessActionType.ToString();
            var info = businessActionType.GetType().GetField(value);
            var data = info.GetCustomAttributes(typeof(BusinessAttribute), false);
            if (data != null && data.Length > 0)
            {
                BusinessAttribute business = data[0] as BusinessAttribute;
                return business?.BusinessTypeName;
            }
            return value;
        }

    }
}
